/*
 * @Author: crissu 13750782397@163.com
 * @Date: 2024-05-22 01:38:28
 * @LastEditors: crissu 13750782397@163.com
 * @LastEditTime: 2024-06-06 01:57:05
 * @FilePath: /try_concurrence/main.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package main

import (
	"fmt"
	patterns "try_concurrence/Patterns"
)

func main() {
	// anytest.ControlGroutineNumsByChan()
	// anytest.ControlGroutineNumsBySync()
	// anytest.ControlGroutineNumsBySyncAndChan()
	// anytest.ControlGroutineNumsBySyncAndChan2()
	// anytest.ControlGroutineNumsByGsema()
	// anytest.ControlGroutineNumsByGsema2()
	// anytest.ControlGroutineNumsBySmart()
	// testAny()
	// memoryaccesssynchronization.TryRWMutex()
	// memoryaccesssynchronization.TryRWMutex()
	// memoryaccesssynchronization.TryCond1()
	// memoryaccesssynchronization.TryCond2()
	// memoryaccesssynchronization.TryOnce()
	// memoryaccesssynchronization.TryPool()
	// deadlockslivelocksandstarvation.TryDeadlocks()
	// deadlockslivelocksandstarvation.TryLiveLocks()
	// deadlockslivelocksandstarvation.TryStarvation()
	// channels.TryChannels()
	// channels.TryChannels1()
	// patterns.TryConfinement1()
	// patterns.TryConfinement2()
	// patterns.TryConfinement3()
	// patterns.TryCancellation()
	// patterns.TryOrChannel1()
	// patterns.TryOrChannel2()
	// patterns.TryErrorHandling()
	// patterns.TryPipelines()
	// patterns.TryPipelines2()
	// patterns.TryPipelinesRepeat()
	// patterns.TryFanInAndFanOut02()
	// patterns.TryFanInAndFanOut03()
	// patterns.TryOrDone()
	// patterns.TryTeeChannel()
	// patterns.TryBridgeChannel()
	// patterns.TryQueuing()
	// patterns.TryContext()
	// patterns.TryHeartBeats()
	patterns.TryReplicatedRequest()
	// testAny()
	// testPrintABCByConcurrent()
}

func testPrintABCByConcurrent() {
	chanByte := make(chan struct{}, 1)
	chanNumber := make(chan struct{}, 1)
	one := 1
	a := 'a'
	chanNumber <- struct{}{}
	for {
		select {
		case <-chanByte:
			fmt.Println(string(a))
			a++
			chanNumber <- struct{}{}
		case <-chanNumber:
			fmt.Println(one)
			one++
			if one == 12 {
				return
			}
			chanByte <- struct{}{}
		}
	}
}

func testAny() {
	nums := []int{1, 2, 3}
	fmt.Println(nums[3:])
}
